;; -*- coding: utf-8 -*-

;; Info node: emacs(top)->Emacs Lisp Packages
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Packages.html#Packages
;; http://ergoemacs.org/emacs/emacs_package_system.html

(defun fetch-package (package &optional min-version no-refresh)
  "Ask elpa to install given PACKAGE.

Token from: https://github.com/purcell/emacs.d/blob/master/init-elpa.el"
  (if (package-installed-p package min-version)
      t
    (if (or (assoc package package-archive-contents) no-refresh)
        (package-install package)
      (progn
        (package-refresh-contents)
        (fetch-package package min-version t)))))

(when (require 'package nil t)

  (require 'cl)

  ;; fix a package.el bug
  ;; https://github.com/bbatsov/prelude/blob/master/prelude/prelude-packages.el
  ;; http://melpa.milkbox.net/
  (setq url-http-attempt-keepalives nil)

;;; Standard package repositories
;(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
;; We include the org repository for completeness, but don't normally
;; use it.

(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(when (< emacs-major-version 24)
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
;;; Also use Melpa for most packages
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))

(setq package-enable-at-startup nil)  ; 避免在处理完 init.el 后再次加载扩展包
(package-initialize)                  ; 由于在启动时就配置包了，所以应该加载包

(dolist (package '(
                 ace-jump-mode                      ; https://github.com/winterTTr/ace-jump-mode
                 smex
                 csharp-mode                        ; http://code.google.com/p/csharpmode/
                 ))
(fetch-package package)))

(provide 'conf-package)

;; Local Variables:
;; no-byte-compile: t
;; End:
